package ru.spb.nicetu.altx.mnemo.node.factory;

import ru.spb.nicetu.altx.mnemo.node.INode;
import ru.spb.nicetu.altx.mnemo.node.LoadMemoryTaskNode;
import ru.spb.nicetu.altx.mnemo.node.LoadTaskNode;
import ru.spb.nicetu.altx.mnemo.node.StoreMemoryTaskNode;
import ru.spb.nicetu.altx.mnemo.node.StoreTaskNode;
import ru.spb.nicetu.altx.mnemo.node.TaskNode;

public class TaskNodeFactory extends NodeFactory {

  public enum TaskTypes {
    NORMAL, LOAD, STORE, LOAD_MEMORY, STORE_MEMORY, LOAD_TO_MEMORY
  };

  private String mSimpleFuncClassName;
  private TaskTypes mTaskType;
  private String mComment;

  public TaskNodeFactory(String simpleFuncClassName, String taskTypeName) {
    if (taskTypeName == null)
      this.mTaskType = TaskTypes.NORMAL;
    else {
      try {
        this.mTaskType = TaskTypes.valueOf(taskTypeName);
      } catch (Throwable t) {
        this.mTaskType = TaskTypes.NORMAL;
      }
    }
    this.mSimpleFuncClassName = simpleFuncClassName;
  };

  public TaskNodeFactory(String simpleFuncClassName, TaskTypes taskType) {
    this.mSimpleFuncClassName = simpleFuncClassName;
    this.mTaskType = taskType;
  };

  public TaskNodeFactory(String simpleFuncClassName, String taskTypeName, String comment) {
	  this(simpleFuncClassName, taskTypeName);
	  this.mComment = comment;
  }

  public TaskTypes getTaskType() {
    return mTaskType;
  }

  public String getComment() {
    return mComment;
  }

  protected INode createNode(String name) {
    INode node = null;
    final String funcClassName = mSimpleFuncClassName;
    switch (mTaskType) {
    case LOAD:
      node = new LoadTaskNode(name, funcClassName);
      break;
    case STORE:
      node = new StoreTaskNode(name, funcClassName);
      break;
    case LOAD_MEMORY:
      node = new LoadMemoryTaskNode(name, funcClassName);
      break;
    case STORE_MEMORY:
      node = new StoreMemoryTaskNode(name, funcClassName);
      break;
    case LOAD_TO_MEMORY:
      node = new LoadToMemoryTaskNode(name, funcClassName);
      break;
    default:
      node = new TaskNode(name, funcClassName);
      break;
    }
    return node;
  }
  
  public String getSimpleFuncClassName() {
    return mSimpleFuncClassName;
  }
}
